/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "StdAfx.h"
#include ".\phantommenu.h"

CPhantomMenu::CPhantomMenu(void)
: aMenu(SSI_NULL)
{
}

CPhantomMenu::~CPhantomMenu(void)
{
}

int CPhantomMenu::FunctionProcessor(SSI_FunctionAPI& theAPI)
{

	if(theAPI.m_FunctionName == "Select"){
		SetActive();
		//MenuID = aMenu->GetMenuItemID(Num);
		//i.Data = (SSI_INT64)List->GetCount();
		//theAPI.m_ReturnStatus = theAPI.SetReturnData(&i);
	}else{
		return CPhantomWindow::FunctionProcessor(theAPI);
	}

/*
	MenuID = Menu->GetMenuItemID(Num);
	DWORD wParam = 0;
	wParam = 0;
	wParam |= MenuID;
	if(Command == "Select")
	{
		if(Win->PostMessage(WM_COMMAND, wParam, 0))
		{
			return TRUE;
		}
		else
		{
			Error.Format(ERR00036, (LPCTSTR)Command, Num);
			LogError(Error);
			return FALSE;
		}
	}
	else if(Command == "IsChecked")
	{
		Return->Type->Format("bool");
		if(Menu->GetMenuState(MenuID, MF_BYCOMMAND) & MF_CHECKED)
		{
			Return->Data->Format("true");
		}
		else
		{
			Return->Data->Format("false");
		}
		return TRUE;
	}
	else if(Command == "IsEnabled")
	{
		Return->Type->Format("bool");
		if(Menu->GetMenuState(MenuID, MF_BYCOMMAND) & MF_GRAYED)
		{
			Return->Data->Format("false");
		}
		else
		{
			Return->Data->Format("true");
		}
		return TRUE;
	}

*/




	return 1;
}

CPhantomWindow* CPhantomMenu::MakeWindow(void)
{
	return new CPhantomMenu();
}


int CPhantomMenu::Attach(HWND InWnd)
{
	aMenu = new CMenu();
	MyWin = InWnd;
	return aMenu->Attach((HMENU)MyWin);

}

int CPhantomMenu::Detach(void)
{
	MyWin = 0;
	if(aMenu){
		aMenu->Detach();
		delete aMenu;
		aMenu = 0;
	}
	return 1;

}
